package com.szxy;

import com.szxy.pojo.Users;
import com.szxy.service.MyMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zwz
 * @Date:2020/7/16 21:55
 * @Description:com.szxy
 * @Version:1.0
 * 启动器
 **/
@SpringBootApplication
@RestController
public class ProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    @Autowired
    private MyMessageService messageService;

    //1. 发送普通文本消息
    @GetMapping("/send/txt/{msg}")
    public ResponseEntity<String> send(@PathVariable String msg) {
        this.messageService.send(msg);
        return ResponseEntity.ok().body("发送消息成功！");
    }

    //2. 发送带有标签 tag 消息
    @GetMapping("/send/tag/{msg}/{tag}")
    public ResponseEntity<String> send(
            @PathVariable String msg,
            @PathVariable String tag) {
        this.messageService.send(msg, tag);
        return ResponseEntity.ok().body("发送消息成功！");
    }

    //3. 发送对象消息
    @GetMapping("/send/obj")
    public ResponseEntity<String> send(Users user, String tag) {
        this.messageService.send(user, tag);
        return ResponseEntity.ok().body("发送消息成功！");
    }

    //4. 发送事务消息
    @GetMapping("/send/trans")
    public ResponseEntity<String> sendMsg(Users user, int type) {
        this.messageService.sendTransMsg(user, type);
        return ResponseEntity.ok().body("发送消息成功！");
    }

    //5. 发送可手动 pull 拉取消息
    @GetMapping("/send/txt/{msg}")
    public ResponseEntity<String> sendPull(@PathVariable  String msg) {
        this.messageService.sendMassiveMessage(msg);
        return ResponseEntity.ok().body("发送消息成功！");
    }

}
